package com.ld.web.controller;

import com.ld.common.R;
import com.ld.web.dto.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/test")
public class TestController {

    @Value("${my.number}")
    private Integer randomNum;

    @Autowired
    private Environment env;//动态获取属性文件中的值

    @RequestMapping(value = "random",method = RequestMethod.GET)
    public R random(){
       String aaa = env.getProperty("my.number");
        System.out.println(String.valueOf(randomNum)+","+aaa);
//        return R.ok(String.valueOf(randomNum)+","+aaa);
        return R.ok("你好！！！～");
    }

    @RequestMapping(value = "obj",method = RequestMethod.POST)
    public R test(@RequestBody List<Test> obj){
        return R.ok(String.valueOf(randomNum)+","+111);
    }
}
